//
//  AppDelegate.m
//  INAlienLand
//
//  Created by dllo on 15/6/29.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import "recommendInterfaceViewController.h"
#import "positionInterfaceViewController.h"
#import "oneselfInterfaceViewController.h"
#import "bargainInterfaceViewController.h"
#import "destinationInterfaceViewController.h"
#import "CCAudioPlayer.h"
#import <AVFoundation/AVFoundation.h>



@interface AppDelegate ()
@property (nonatomic,retain)CCAudioPlayer *audioPlayer;
@property (nonatomic,retain)AVAudioPlayer *player;
@end

@implementation AppDelegate

-(void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    

   
    //创建播放器
    self.player = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"在他乡" ofType:@"mp3" ]]  error:nil];
    
    

      //  [self.player play];

        [self.player play];

//    //创建播放器
//    self.player = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"在他乡" ofType:@"mp3" ]]  error:nil];
//    
//    
//        [self.player play];

    recommendInterfaceViewController *recommendbar = [[recommendInterfaceViewController alloc]init];
    UINavigationController *recommendNV = [[UINavigationController alloc]initWithRootViewController:recommendbar];
    
    positionInterfaceViewController *positionbar = [[positionInterfaceViewController alloc]init];
    UINavigationController *positionNV = [[UINavigationController alloc]initWithRootViewController:positionbar];
    
    destinationInterfaceViewController *destinationbar = [[destinationInterfaceViewController alloc]init];
    UINavigationController *destinationNV = [[UINavigationController alloc]initWithRootViewController:destinationbar];
    destinationbar.player = self.player;
    
    oneselfInterfaceViewController *oneselfbar = [[oneselfInterfaceViewController alloc]init];
    UINavigationController *oneselfNV = [[UINavigationController alloc]initWithRootViewController:oneselfbar];
    
    bargainInterfaceViewController *bargainbar = [[bargainInterfaceViewController alloc]init];
    UINavigationController *bargainNV = [[UINavigationController alloc]initWithRootViewController:bargainbar];
    
    recommendNV.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"推荐" image:[UIImage imageNamed:@"iconfont-browse.png"] tag:10000];
    
    positionNV.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"位置" image:[UIImage imageNamed:@"iconfont-box.png"] tag:10001];
    
    oneselfNV.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的" image:[UIImage imageNamed:@"iconfont-toys.png"] tag:10002];
    
    destinationNV.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"目的地" image:[UIImage imageNamed:@"iconfont-auto-2.png"] tag:10003];
    
    bargainNV.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"特价" image:[UIImage imageNamed:@"iconfont-cart.png"] tag:10004];

    //[self _resetStreamer];
    UITabBarController *begin = [[UITabBarController alloc]init];
    begin.viewControllers = [NSArray arrayWithObjects:recommendNV,destinationNV,positionNV,bargainNV,oneselfNV, nil];
    self.window.rootViewController = begin;
    begin.edgesForExtendedLayout = UIRectEdgeNone;
    
    
    
    
    [begin release];
    [bargainbar release];
    [bargainNV release];
    [positionbar release];
    [positionNV release];
    [oneselfbar release];
    [oneselfNV release];
    [recommendbar release];
    [recommendNV release];
    [destinationbar release];
    [destinationNV release];
    return YES;
}
//- (void)_resetStreamer
//{
//    if (_audioPlayer) {
//        [_audioPlayer dispose];
//        if (/* DISABLES CODE */ (!1)) {
//            [_audioPlayer removeObserver:self forKeyPath:@"progress"];
//            [_audioPlayer removeObserver:self forKeyPath:@"playerState"];
//        }
//        _audioPlayer = nil;
//    }
//    
//    
//    if (1) {
//        
//        //Track *track = [_tracks objectAtIndex:_currentTrackIndex];
//     
//               _audioPlayer = [CCAudioPlayer audioPlayerWithContentsOfURL:[NSURL URLWithString:@"http://pkstatic.b0.upaiyun.com/upload/20150708/cdd719cbac967bcc6b6410490b284c38.MP3"]];
//        if (0) {
//            typeof(self) __weak weakSelf = self;
//            [_audioPlayer trackPlayerProgress:^(NSTimeInterval progress) {
//                          } playerState:^(CCAudioPlayerState playerState) {
////                MusicViewController *mu = weakSelf;
//            }];
//        }else{
//            [_audioPlayer addObserver:self forKeyPath:@"progress" options:NSKeyValueObservingOptionNew context:nil];
//            [_audioPlayer addObserver:self forKeyPath:@"playerState" options:NSKeyValueObservingOptionNew context:nil];
//        }
//        
//        [_audioPlayer play];
//    }else{
//        
//    }
//}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    [_player stop];
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

